package main

import (
	"bufio"
	"flag"
	"fmt"
	"os"
	"sdwebuiapi/sdwebuiapi"
	"sdwebuiapi/task_process"
	"sdwebuiapi/utils"
	"strings"

	"github.com/gogf/gf/frame/g"
)

var gfcfgFile = flag.String("gffile", "config.yml", "the gf config file")
var gfcfgPath = flag.String("gfpath", "./etc", "the gf config file")

func main() {
	// ...
	g.Cfg().SetPath(*gfcfgPath)
	g.Cfg().SetFileName(*gfcfgFile)

	reader := bufio.NewReader(os.Stdin)

	taskServer := task_process.StartServer()
	var name string
	fmt.Println("请选择操作： 1. 输入文件路径:")
	//fmt.Scanf("%s", &name)
	name, _ = reader.ReadString('\n')
	name = strings.TrimSpace(name) // 去除输入的前后空格和换行符

	//c := make(chan os.Signal)
	//signal.Notify(c)

	if name == "1" {
		fmt.Println("请输入文件路径：")
		filePath, _ := reader.ReadString('\n')
		filePath = strings.TrimSpace(filePath) // 去除输入的前后空格和换行符
		list, err := utils.ReadExcel(filePath)
		if err != nil {
			return
		}
		//fmt.Println("list is ", list)
		for _, val := range list {
			fmt.Println("val is ", val)
			sdwebuiapi.Txt2ImgRequest(val)
		}

	} else if name == "2" {

		fmt.Println("请输入文件路径：")
		filePath, _ := reader.ReadString('\n')
		filePath = strings.TrimSpace(filePath) // 去除输入的前后空格和换行符
		list, err := utils.ReadExcel(filePath)
		if err != nil {
			return
		}
		res, err := utils.TranslateToEN(list)
		if err != nil {
			fmt.Println("翻译失败")
		}
		//fmt.Println("翻译结果：", res)
		for _, val := range res {
			fmt.Println("val is ", val)
			sdwebuiapi.Txt2ImgRequest(val)
		}

	} else if name == "3" {
	} else if name == "4" {
	} else {
		fmt.Println("输入错误")
	}

	var name1 string
	fmt.Println("程序运行结束，按任意键退出")
	fmt.Scanf("%s", &name1)
	taskServer.Stop()

}
